import axios from 'axios';
import qs from 'query-string';

export interface CityId {
    id: number;
}

export interface CityRecord {
    id: number;
    name: string;
    code: string;
    status: number;
    created_at: number;
    updated_at: number;
    deleted_at: number;
}

export interface CityListRes {
    list: CityRecord[];
    total: number;
}

export interface CityModel {
    id: number;
    name: string;
    code: string;
    status: number;
}

export interface CityParams extends Partial<CityRecord> {
    page: number;
    pageSize: number;
}

/**
 * 获取城市列表
 * @param params
 */
export function queryCityList(params: CityParams) {
    return axios.get<CityListRes>('/admin/city/index', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 获取城市详情
 * @param params
 */
export function queryCityOne(params: CityId) {
    return axios.get<CityRecord>('/admin/city/detail', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 提交城市表单（创建/更新）
 * @param data
 */
export function submitCityForm(data: any) {
    return axios.post('/admin/city/submit', data);
}

/**
 * 删除城市
 * @param id
 */
export function delCity(id: number) {
    return axios.post('/admin/city/delete', { id });
}
